using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.Data.Utils;
using DemoCenter;
using Microsoft.Win32;
using System.Diagnostics;
using System.IO;

namespace DevExpress.Demos.DemoCenter {
    static class Program {
        [STAThread]
        static void Main(string[] args) {
            string wpfDemoCenterExe = null;
            if(IsFramework4_0Inslatted) {
                string executablePath = Application.ExecutablePath;
                int i = executablePath.LastIndexOf('\\');
                if(i >= 0)
                    executablePath = executablePath.Remove(i);
                wpfDemoCenterExe = executablePath + "\\WPF\\DevExpress.DemoCenter.Xpf.exe";
                if(!File.Exists(wpfDemoCenterExe))
                    wpfDemoCenterExe = null;
            }
            if(wpfDemoCenterExe != null)
                Process.Start(wpfDemoCenterExe);
            else
                (new WinProgram()).Run(args);
        }

        static bool IsFramework3_5Installed {
            get {
                Version minimalVersion = new Version(3, 5, 30729, 1);
                Version v = Helpers.GetFrameworkVersion();
                return v >= minimalVersion;
            }
        }

        static bool IsFramework4_0Inslatted {
            get {
                const string client4_0 = "\\Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client";
                const string full4_0 = "\\Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full";

                object res = Registry.GetValue(Registry.LocalMachine + client4_0, "Install", (int)0);
                if(res != null && (int)res == 1)
                    return true;
                res = Registry.GetValue(Registry.LocalMachine + full4_0, "Install", (int)0);
                return res != null && (int)res == 1;
            }
        }
    }
}
